package it.aupapp.web.style;

import it.aupapp.model.Style;
import it.happyisland.framework.web.AupServlet;
import it.happyisland.framework.web.Bean;
import it.happyisland.framework.web.Param;
import it.happyisland.framework.web.Path;

import java.util.List;

public class StyleServlet extends AupServlet{
		
	private static final long serialVersionUID = 1L;
	
	StyleDao dao = new StyleDao();
	
	@Path("/crud")
	public Object page(){
		return forward("/style.html");
	}
	
	@Path("/list")
	public Object list(){
		List<Style> styles = dao.loadAll();
		
		return json(convertToJson(styles));
	}
	
	@Path("/add")
	public String add(@Bean Style style){
		try{
			dao.save(style);
		} catch(Throwable t){
			t.printStackTrace();
			return t.getMessage();
		}
		
		return "ok";
	}
	@Path("/remove")
	public String remove(@Param("name") String name){
		try{
			dao.remove(name);
		} catch(Throwable t){
			t.printStackTrace();
			return t.getMessage();
		}
		
		return "ok";
	}
	
	
	
}
